﻿#region File Info Header
/*________________________________________________________________________________________

  Copyright (C) 2011 Jason Zhang, eagleboost@msn.com

  * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
  * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

________________________________________________________________________________________*/
#endregion File Info Header

namespace EagleBoost.Wpf.Presentation.Converters
{
  using System.Windows.Data;
  using System;
  using System.Globalization;

  /// <summary>
  /// Invert the boolean value
  /// </summary>
  [ValueConversion(typeof(bool), typeof(bool))]
  public class BooleanInverseConverter : ConverterMarkupExtension<BooleanInverseConverter>, IValueConverter
  {
    #region IValueConverter Members
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      if (value is bool)
      {
        var boolValue = (bool)value;
        return !boolValue;
      }
      return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      if (value is bool)
      {
        var boolValue = (bool)value;
        return !boolValue;
      }
      throw new ArgumentException("The value must be a boolean");
    }
    #endregion IValueConverter Members
  }
}
